package com.misolab.utility.speedmate.util;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.misolab.utility.speedmate.R;

public class StartAdapter extends BaseAdapter {

	LayoutInflater inflater;
	ArrayList<String> datas = new ArrayList<String>();
	
	public String getString(int index){
		return datas.get(index);
	}
	
	public StartAdapter(Context context) {
		super();
		inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		
		for (int i = -10; i < 11; i++) {
			datas.add(""+i);
		}
	}

	@Override
	public int getCount() {
		return datas.size();
	}

	@Override
	public Object getItem(int index) {
		return datas.get(index);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	
	class ViewWrapper{
		View view;

		public ViewWrapper(View view) {
			super();
			this.view = view;
		}
		
		public void setText(String text){
			TextView tv = (TextView) view.findViewById(R.id.item);
			tv.setText(text);
		}
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.item, null);
		}
		
		ViewWrapper vw = (ViewWrapper) convertView.getTag(); 
		if (vw == null) {
			vw = new ViewWrapper(convertView);
			convertView.setTag(vw);
		}
		
		vw.setText( datas.get(position) );
		return convertView;
	}

}
